<template>
  <div class="chart-card">
    <div class="chart-header">
      <h3>演示教程</h3>
      <div class="stats">
        <span class="value">36,256</span>
        <span class="change down">↓5.27%</span>
        <span class="compare">环比上月</span>
      </div>
    </div>
   <e-charts class="chart" :option="option" />
  </div>
</template>

<script setup>
import { ref ,computed } from 'vue'
import VChart from 'vue-echarts'

  const data=ref([
    {value:11,name:'A'},
    {value:31,name:'B'},
    {value:75,name:'C'},
    {value:25,name:'D'},
    {value:16,name:'E'},
  ])
 
const option=computed(()=>{
  return{
    xAxis:{
      type:'category',
      data:data.value.map(v=>v.name)
    },
    yAxis:{
      type:'value',
    },
    series:[
      {
        type:'line',
        data:data.value.map(v=>v.value)
      }
    ]
  }
})

setInterval(()=>{
  data.value=data.value.map(item=>({
    ...item,
    value:Math.random()*100,  //Math()随机函数，这里是随机生成100以内的数字
  }))
},1000) 
</script>

<style scoped>
.chart-card {
  background: #fff;
  padding: 20px;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.chart{
  height: 400px;
}
</style>